<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品投出片平均耗时统计列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>统计日期：</label>
                                <select name="signDate" th:with="si=${siInOutLotSignDateList}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${si}" th:text="${dict.signDateName}" th:value="${dict.signDate}"></option>
                                </select>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" name="partName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="report:partavertimesta:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>

            <div class="row">
                <div class="col-sm-10">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>统计折线图</h5>
                        </div>
                        <div class="ibox-content">
                            <div class="echarts" id="echarts-line-chart" style="height: 500px;"></div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: echarts-js" />
    <script th:inline="javascript">
        const prefix = ctx + "report/partavertimesta";
        var column = [
            {
                checkbox: true
            },
            {
                field: 'NO',
                title: "序号",
                width: 50,
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
            {
                field: 'signDate',
                title: '统计日期',
                sortable: true
            },
            {
                field: 'materialType',
                title: '产品类型',
                sortable: true
            },
            {
                field: 'partName',
                title: '产品名称',
                sortable: true
            },
            {
                field: 'consumeHours',
                title: '投出片平均耗时'
            },
            {
                field: 'sumQty',
                title: '该产品片数'
            },
            {
                field: 'sumLot',
                title: '该产品卡数'
            },
            {
                field: 'createTime',
                title: '创建时间',
                visible: false
            }
        ];

        // 投出片日期列表
        var siInOutLotSignDateList = [[${siInOutLotSignDateList}]];
        var xData = [];// x轴的刻度

        // 重点产品进度统计
        var staProduct = [[${importantPart}]];
        var siPartAverTimeList = [[${siPartAverTimeList}]];
        // 彩虹七色+黑色
        const colorstrs = [
            '#f30303',
            '#9b5002',
            '#ffff00',
            '#06f306',
            '#05fafa',
            '#0707ef',
            '#7f14e7',
            '#000000'
        ];
        var chartOptionSeries = [];
        var chartOptions = {
            title: {
                text: '产品投出片平均耗时统计'
            },
            tooltip: {
                trigger: 'axis',
                // axisPointer:{
                //     type:'cross', // 伴随着鼠标的移动，横向的虚线
                // }
            },
            legend: {
                itemStyle: { opacity: 0 },//去圆点
                textStyle: {
                    fontSize: 14,//字体大小
                    color: '#000000'//字体颜色
                },
                data: staProduct
            },
            grid: {
                left: '10%',
                right: '10%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}   //下载为图片
                }
            },
            xAxis: {
                name:'统计月份',
                type: 'category',
                boundaryGap: false,     //控制折线起点
                data: xData
            },
            yAxis: {
                name:'小时',
                // min:0,  //取0为最小刻度
                // max: 100, //取100为最大刻度
                //
                // min:'dataMin', //取最小值为最小刻度
                // max: 'dataMax', //取最大值为最大刻度

                min: 0, //取最小值为最小刻度
                max: 'dataMax', //取最大值为最大刻度

                // min: function(value) {//取最小值向下取整为最小刻度
                //     return Math.floor(value.min)
                // },
                // max: function(value) {//取最大值向上取整为最大刻度
                //     return  Math.ceil(value.max)
                // },

                scale: true, //自适应
                minInterval: 0.1, //分割刻度
                axisLabel:{
                    color: "#000000",
                    fontSize: 13,
                    showMinLabel: true, //不显示最小刻度线值
                    showMaxLabel: true //不显示最大刻度线值
                },
                axisLine: {
                    lineStyle: {
                        color: "#000000", //最左侧Y轴颜色
                    }
                },
                splitLine: { //刻度的多条横线
                    show: true
                }
            },
            series: chartOptionSeries
        };

        $(function() {
            var options = {
                url: prefix + "/list",
                exportUrl: prefix + "/export",
                modalName: "产品投出片平均耗时统计",
                sortName: "signDate",
                columns: column
            };
            $.table.init(options);

            var chartDom = document.getElementById("echarts-line-chart");
            var lineChart = echarts.init(chartDom);
            //设置参数
            setChartOptions();
            // 指定图表的配置项和数据

            // 使用刚指定的配置项和数据显示图表。
            lineChart.setOption(chartOptions);
            $(window).resize(lineChart.resize);
        });

        function setChartOptions() {
            // 先设置x轴的刻度
            siInOutLotSignDateList.forEach(e => {
                xData.push(e.signDateName);
            });
            siPartAverTimeList.forEach( (item, index) => {
                chartOptionSeries.push({
                    type: 'line',
                    name: item.partName,
                    itemStyle: {
                        normal: {
                            color: colorstrs[index],
                            lineStyle: {
                                color: colorstrs[index]
                            }
                        }
                    },
                    data: item.consumeHours
                });
            });
        }
    </script>
</body>
</html>